package web.filter;


import javax.servlet.*;
import java.io.IOException;

public class EncodingFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("创建Filter");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
            /*过滤器条件*/
              servletRequest.setCharacterEncoding("UTF-8");
        // 处理响应乱码
                servletResponse.setContentType("text/html;charset=utf-8");
              System.out.println("啊啊啊我进来了！");
              /*放行*/
             filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        System.out.println("销毁Filter");
    }
}
